from models.user import User
from utils.sqlutils import SqlUtils
from sqlmap.punchsqlmap import SqlMap as PunchSqlMap


class Punch:
    def __init__(self):
        self.sqlutils = SqlUtils()
        self.user = User()

    def punch_list(self):
        data = self.sqlutils.execute(PunchSqlMap.get("list"))
        punch_list = []
        for row in data.get("content"):
            punch = {}
            punch["id"] = row[0]
            punch["user"] = self.user.user_info(id=row[1]).get("name")
            punch["image_path"] = row[2]
            punch["viewname"] = row[3]
            punch_list.append(punch)
        return punch_list

    def punch_info(self):
        return self.sqlutils.execute(PunchSqlMap.get("info"))

    def punch_create(self, **kwargs):
        return self.sqlutils.execute(PunchSqlMap.get("create").format(**kwargs))

    def punch_delete(self, **kwargs):
        return self.sqlutils.execute(PunchSqlMap.get("delete").format(**kwargs))

    def punch_edit(self, **kwargs):
        return self.sqlutils.execute(PunchSqlMap.get("edit").format(**kwargs))

    def punch_exec(self,key, **kwargs):
        return self.sqlutils.execute(PunchSqlMap.get(key).format(**kwargs))

if __name__ == '__main__':
    punch = Punch()
    punch.punch_list()
    # print(punch.punch_list())
